<template>
  <div class="tools-container">
    <h1 class="title">开发者收藏导航</h1>
    <!-- 侧边导航 -->
    <el-affix position="bottom" target=".tools-container" :offset="20">
      <div class="sidebar">
        <button v-for="(items) in bookmarks" :key="items.id" class="sidebar-button"
          @click="scrollToCategory(items.id)">
          {{ items.name }}
        </button>
      </div>
    </el-affix>
    <!-- 所有网站卡片列表 -->
    <div class="card-sections">
      <TransitionGroup name="fade">
        <div v-for="(items) in bookmarks" :key="category" class="category-section"
          :id="'category-' + items.id ">
          <h2 class="category-title">{{ items.name }}</h2>
          <div class="card-grid">
            <div v-for="item in items.links" :key="item.name" class="card">
              <a :href="item.url" target="_blank" class="card-link">
                <div class="card-header">
                  <img v-if="item.icon_url" :src="item.icon_url" alt="" class="card-icon" />
                  <h3 class="card-title">{{ item.title }}</h3>
                </div>
                <p class="card-description">{{ item.description }}</p>
              </a>
            </div>
          </div>
        </div>
      </TransitionGroup>
    </div>
  </div>
</template>

<script setup>
import { ElAffix } from 'element-plus'
// 示例数据 - 可以从 API 获取或动态添加
// import { bookmarks } from './data.js'
import { onMounted } from 'vue'
import { fetchLinkList } from '@/service/module/link.js'
const bookmarks = ref([])
// 滚动到指定分类
const scrollToCategory = (category) => {
  const element = document.getElementById('category-' + category)
  if (element) {
    element.scrollIntoView({ behavior: 'smooth' })
  }
}
onMounted(async() => {
  bookmarks.value = await fetchLinkList()
})
</script>

<style lang="scss" scoped>
.tools-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  font-family: 'Segoe UI', sans-serif;
  position: relative;
}

.title {
  text-align: center;
  font-size: 2rem;
  color: #facc15;
  margin-bottom: 30px;
  animation: fadeInDown 1s ease forwards;
}

/* 侧边栏 */
.sidebar {
  position: fixed;
  right: 30px;
  top: 120px;
  max-height: 80vh;
  overflow-y: auto;
  background: rgba(26, 32, 44, 0.95); // 更清晰的背景
  border-radius: 10px;
  padding: 12px;
  z-index: 10;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px); // 毛玻璃效果
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(79, 70, 229, 0.4);
  }

  .sidebar-button {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #4f46e5, #6366f1); // 主题渐变色
    color: white;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    position: relative;

    &:hover {
      background: linear-gradient(135deg, #6366f1, #8b5cf6);
      transform: scale(1.03);
      box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    }

    &.active,
    &:active {
      background: linear-gradient(135deg, #8b5cf6, #a855f7);
      transform: scale(1.05);
      box-shadow: 0 6px 16px rgba(126, 34, 206, 0.4);
      font-weight: bold;
    }
  }
}

/* 分类内容区域 */
.card-sections {
  margin-top: 20px;
}

.category-title {
  font-size: 1.5rem;
  color: #6366f1;
  margin-bottom: 20px;
  border-left: 4px solid #6366f1;
  padding-left: 10px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 60px;
}

.card {
  background: #1a202c;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.1);

  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(79, 70, 229, 0.3);
  }

  .card-link {
    display: block;
    padding: 20px;
    color: inherit;
    text-decoration: none;
  }

  .card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }

  .card-icon {
    width: 30px;
    height: 30px;
    object-fit: contain;
  }

  .card-title {
    font-size: 1.1rem;
    color: #facc15;
  }

  .card-description {
    font-size: 0.9rem;
    color: #ccc;
  }
}

// 动画效果
.fade-enter-active,
.fade-leave-active {
  transition: all 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
  transform: translateY(20px);
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>